//
//  MainFirst_Magazine_TBV_GoodsCell_WX.m
//  ZITHER
//
//  Created by weixin on 2018/10/19.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainFirst_Magazine_TBV_GoodsCell_WX.h"
    @implementation MainFirst_Magazine_TBV_GoodsCell_WX

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor randomColor];
    
    [self setBorderWithHiddem:YES Color:baseColorLight width:0.5 Radius:10];
    [self.viewBorder mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-25);
    }];
    
    [self addSubview:self.cover];
    [self addSubview:self.text];
    [self addSubview:self.title];
    [self addSubview:self.topView];
    self.topView.backgroundColor = [UIColor randomColor];
    
    [self.topView addSubview:self.lab];
    [self.topView addSubview:self.rightLineView];
    [self.topView addSubview:self.LineLeftView];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self).offset(0);
        make.height.mas_equalTo(20);
    }];

    [self.lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_top).offset(0);
        make.centerX.equalTo(self.topView.mas_centerX).offset(0);
    }];
    
    [self.LineLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lab.mas_centerY).offset(0);
        make.left.equalTo(self).offset(19);
        make.right.equalTo(self.lab.mas_left).offset(-33);
        make.height.mas_equalTo(1);
    }];

    [self.rightLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lab.mas_centerY).offset(0);
        make.right.equalTo(self).offset(-19);
        make.left.equalTo(self.lab.mas_right).offset(33);
        make.height.mas_equalTo(1);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom).offset(24);
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self.cover.mas_left).offset(-5);
    }];

    [self.text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(4);
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self.cover.mas_left).offset(-5);
    }];

    self.cover.backgroundColor = [UIColor redColor];
    [self.cover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.title.mas_bottom).offset(5);
        make.right.equalTo(self).offset(-30);
        make.height.width.mas_equalTo(60);
        make.bottom.equalTo(self).offset(-24-25-20);
    }];
    
}

-(void)setModel:(HomePageDetailModelGoodsList *)model{
    [self.cover sd_setImage:model.imageDefault];
    
    self.cover.hidden = YES;
    if ([model.type isEqualToString:@"1"]) {
        //brandNameNative goodNameNative 品牌 _goodsId
        self.title.text = model.brandNameNative;
        self.text.text = model.goodName;
        self.cover.hidden = NO;
    }else if ([model.type isEqualToString:@"2"]){
        //seriesNameNative brandNameNative 系列 _seriesId
        self.title.text = model.seriesNameNative;
        self.text.text = model.brandNameNative;
    }else if ([model.type isEqualToString:@"3"]){
        //brandNameNative brandName 型号 _brandId
        self.title.text = model.brandNameNative;
        self.text.text = model.brandName;
    }
}

-(void)setIndex:(NSInteger)index{
    
    if (index == 0) {
        self.topView.hidden = NO;
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self).offset(0);
            make.top.equalTo(self).offset(50);
            make.height.mas_equalTo(20);
        }];
        [self.viewBorder mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(50+50);
            make.bottom.equalTo(self).offset(-15);
        }];
        
        [self.title mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_bottom).offset(10+50);
//            make.top.equalTo(self).offset(24+50);
        }];
        [self.cover mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-37);
        }];
    }else if(index == 1){
        self.topView.hidden = YES;
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.height.mas_equalTo(0);
        }];
        [self.viewBorder mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(-15);
        }];
        
        [self.title mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_bottom).offset(35);

//            make.top.equalTo(self).offset(24);
        }];
        [self.cover mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-37);
        }];
    }else{
        self.topView.hidden = YES;
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.height.mas_equalTo(0);
        }];
        [self.viewBorder mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(-50);
        }];
        
        [self.title mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_bottom).offset(35);

//            make.top.equalTo(self).offset(24);
        }];
        [self.cover mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-75);
        }];
    }
}
-(BaseLab *)title{
    if (!_title) {
        _title = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"" font:12 textColor:nil isBold:NO numberOfLines:1];
        _title.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];

    }
    return _title;
}

-(BaseLab *)text{
    if (!_text) {
        _text = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"" font:24 textColor:nil isBold:YES numberOfLines:1];
        _text.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];

    }
    return _text;
}

-(BaseImageV *)cover{
    if (!_cover) {
        _cover = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        _cover.backgroundColor = [UIColor randomColor];
    }
    return _cover;
}

-(UIView *)LineLeftView{
    if (!_LineLeftView) {
        _LineLeftView = [[UIView alloc]initWithFrame:CGRectMake(19, 20, kScreenW/2.0 -30, 1)];
        _LineLeftView.backgroundColor = baseColorLight;
    }
    return _LineLeftView;
}

-(UIView *)rightLineView{
    if (!_rightLineView) {
        _rightLineView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW - 19, 20, kScreenW/2.0 -30, 1)];
        _rightLineView.backgroundColor = baseColorLight;
    }
    return _rightLineView;
}


-(BaseLab *)lab{
    if (!_lab) {
        _lab = [[BaseLab alloc]initializeFrame:CGRectMake(kScreenW-100, 20, 80, 15) text:@"相关腕表" font:14 textColor: [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1/1.0] isBold:NO numberOfLines:1];
    }
    return _lab;
}

-(UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _topView.backgroundColor = [UIColor randomColor];
    }
    return _topView;
}

@end
